<!-- 实习生证明模板新增、修改 -->
<template>
  <PageHeaderNew :title="title" :breadCrumb="breadCrumb" :showBack="true">
    <template #buts>
      <a-button type="primary" @click="save()">保存</a-button>
    </template>
  </PageHeaderNew>
  <div class="index">
    <a-form
      ref="formRef"
      direction="vertical"
      :model="templateDetail.info"
      :rules="rules"
      label-align="right"
    >
      <a-form-item field="name" label="模板名称">
        <a-input placeholder="模板名称" v-model="templateDetail.info.name" />
      </a-form-item>
      <a-form-item field="explain" label="描述">
        <a-input placeholder="描述" v-model="templateDetail.info.explain" />
      </a-form-item>
      <a-form-item field="courseClassifyId" label="表单与打印">
        <ClassifyInput placeholder="请选择" :classify-tree="[]" />
      </a-form-item>
      <a-form-item field="courseClassifyId" label="审批流程设置">
        <ClassifyInput placeholder="请选择" :classify-tree="[]" />
      </a-form-item>
    </a-form>
  </div>
</template>
<script setup lang="ts">
import * as apiVariation from '@/apis/human/base/variationManager';
import { type TInternshipTemplateAudit } from '@/apis/human/base/variationManager/type';
import { useRoute, useRouter } from 'vue-router';
import { Message } from '@arco-design/web-vue';
import ClassifyInput from './components/ClassifyInput.vue';

const route = useRoute();
const router = useRouter();
const title = ref('新增开具实习证明模板');
const breadCrumb: string[] = ['人事', '异动管理', '新增开具实习证明模板'];
const formRef = ref();
const rules = {
  name: {
    required: true,
    message: '请填写名称',
    trigger: "['change', 'input', 'blur']"
  }
};
const templateDetail = reactive<{ info: TInternshipTemplateAudit }>({
  info: {}
});
//获取实习证明模板详情
const getData = async () => {
  const { id } = templateDetail.info;
  if (!id) return;
  let res = await apiVariation.GetInternshipProofModeAuditById({
    id
  });
  templateDetail.info = res || {};
};
//保存
const save = async () => {
  // 验证表单
  if (await formRef.value.validate()) return;
  let {
    info: { id }
  } = templateDetail;
  let msg = '新增成功';
  // 新增
  if (!id) {
    await apiVariation.PostInternshipProofModeAudit(templateDetail.info);
  } else {
    // 编辑
    await apiVariation.PutInternshipProofModeAudit(templateDetail.info);
    msg = '编辑成功';
  }
  Message.success(msg);
  router.back();
};
const init = () => {
  templateDetail.info.id = route.query.id ? Number(route.query.id) : void 0;
  title.value = '编辑开具实习证明模板';
  if (!templateDetail.info.id) return;
  getData();
};
init();
</script>
<style lang="less" scoped>
.index {
}
</style>
